﻿using System;
using System.Windows.Forms;
using UIExceptionHandler;
using UIExceptionHandler.Interfaces;

namespace UIExceptionHandlerWinForms
{
    public partial class ErrorHandlerForm : Form, IErrorHandlerForm
    {
        public event Action OnSendButtonClick;
        public event Action OnShowErrorLinkClick;
        public event Action OnLogFileLinkClick;
        public event Action OnDebugButtonClick;

        public ErrorHandlerForm()
        {
            InitializeComponent();
            SubscribeEvents();
        }

        private void SubscribeEvents()
        {
            sendButton.Click += (sender, e) => OnSendButtonClick();
            debugButton.Click += (sender, e) => OnDebugButtonClick();
            showErrorLink.Click += (sender, e) => OnShowErrorLinkClick();
            logFileLink.Click += (sender, e) => OnLogFileLinkClick();
        }

        public void SetHeight(int height)
        {
            Height = height;
        }

        public string ExceptionInfoText
        {
            get { return exceptionInfoTextBox.Text; }
            set { exceptionInfoTextBox.Text = value; }
        }

        public string ExceptionDetailText
        {
            get { return detailInfoTextBox.Text; }
            set { detailInfoTextBox.Text = value; }
        }

        public void ShowExceptionInfoTextBox(bool isShow)
        {
            exceptionInfoTextBox.Visible = isShow;
        }

        public void ShowInfoMessageBox(string text, string caption)
        {
            MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public bool ShowQuestionDialog(string text, string caption)
        {
            if (MessageBox.Show(text, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                return true;
            }
            return false;
        }

        public void ShowViewDialog()
        {
            ShowDialog();
        }

        public void UpdateContactEmail(string contactEmail)
        {
            messageLabel.Text += Settings.ProgrammerEmail + ". Thank you!";
        }

        public string ReplyEmail {
            get { return replyEmailTextBox.Text; }
        }
    }
}
